const expressSession = require('express-session')
const redis = require('redis')
const RedisStore = require('connect-redis')(expressSession)
const redisConfig = {
  host: '127.0.0.1',
  port: '16320',
  ttl: 1000 * 60 * 5,
  password: 'u6^8LM*Zme7!Yl4!'
}
const redisClient = redis.createClient(redisConfig.port, redisConfig.host, {
  auth_pass: redisConfig.password
})
redisClient.auth(redisConfig.password, function () {
  console.log('连接成功')
  redisClient.on('ready', res => {
    console.log('redis启动成功')
  })
  redisClient.on('connect', () => {
    console.log('redis connect success')
  })

  redisClient.on('error', err => {
    console.log('redis启动失败', err)
  })
})
const session = {
  store: new RedisStore({ client: redisClient }),
  secret: 'password',
  resave: false,
  saveUninitialized: false,
  cookie: {
    maxAge: 1000 * 60 * 5 // default session expiration is set to 1 hour
  }
}
module.exports = {
  port: 8089,
  session,
  sqldb: {
    db: 'mysql',
    host: '127.0.0.1',
    port: 3306,
    database: 'express_admin',
    username: 'root',
    password: 'fwq123',
    timezone: '+08:00' //for writing to database
  },
  redisConfig,
  SUPER_ROLE_CODE: 'admin',
  admin_password: 'admin',
  saltTime: 6,
  port: 8086, // 生产环境运行端口号
  secretOrKey: 'admin-token', // jwtFromRequest token
  defaultpassword: '123456',
  redisClient
}